package com.yan.project.service;

import com.yan.project.entity.Article;
import com.yan.project.repository.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * TODO
 *
 * @Author: 汪焰
 * @Date: 2020/12/12 21:50
 */
@Service
public class ArticleService {

    @Autowired
    private ArticleMapper articleMapper;

    public List<Article> list() {
        return articleMapper.findAll();
    }

    public Long count() {
        return articleMapper.count();
    }

    public Page<Article> page(Integer pageNum, Integer pageSize) {
        if (pageNum == null || pageNum < 0) {
            pageNum = 0;
        }
        Pageable pageable = PageRequest.of(pageNum, pageSize);
        Page<Article> result = articleMapper.findAll(pageable);
        return result;
    }
}
